package com.wva.redis.serializer;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;

import java.nio.charset.StandardCharsets;

/**
 * @Author: hong
 * @Date: 2025/3/7 14:07:07
 */
@Deprecated
public class CustomRedisSerializer implements RedisSerializer<Object> {
    private ObjectMapper objectMapper;
    public CustomRedisSerializer(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
    }

    @Override
    public byte[] serialize(Object object) throws SerializationException {
        try {
            return objectMapper.writeValueAsString(object).getBytes(StandardCharsets.UTF_8);
        } catch (JsonProcessingException e) {
            throw new SerializationException("对象转json失败");
        }
    }

    @Override
    public Object deserialize(byte[] bytes) throws SerializationException {
        // return objectMapper.readValue(bytes, );
        return null;
    }
}
